﻿using OneP.InfinityScrollView;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ZhanjiRoom : InfinityBaseItem
{
    public Text date, time, name, id, difen, RoomTime, shouShu;
    public RawImage head;
    public string heads;
    public override void Reload(InfinityScrollView _infinity, int _index)
    {
        date.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].Date;
        time.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].Time;
        name.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].RoomName;
        id.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].RoomID.ToString();
        difen.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].Difen.ToString();
        RoomTime.text = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].RoomTime;
        int score= SaveDate.GetInstance().ZjAlllist.historyRooms[_index].RoomScore;
        heads = SaveDate.GetInstance().ZjAlllist.historyRooms[_index].head;
        shouShu.text = score.ToString();
        if (score<=0)
        {
            shouShu.color = new Color(1,0,0,1);
        }
        else
        {
            shouShu.color = new Color(0, 1, 0, 1);
        }
    }
    public void Start()
    {
        DownloadHeadTexture(head, heads);
    }
    public void Getzhanji() {
        MessageManager.GetInstance().Send7134(id.text);
    }
    protected void DownloadHeadTexture(RawImage texture, string url)            //下载头像图片
    {
        //texture = null;
#if WX_SDK
        if (url != null)
        {
            //用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空
            //url = url.Substring(0, url.Length - 1);
            //url += "132";    
            StartCoroutine(DownloadTexture(texture, url));
        }
        else
        {
            Debug.Log("下载头像Texture收到的url为空！");
        }
#else
        url = URLConst.DefaultUserHeadUrl;
        StartCoroutine(DownloadTexture(texture, url));
#endif
    }

    private IEnumerator DownloadTexture(RawImage texture, string url)
    {
        WWW www = new WWW(url);
        yield return www;
        texture.texture = www.texture;
    }
}
